/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package inventory;
import java.sql.*;

/**
 *
 * @author Mark King
 */
public class UserQuery {
    
    public Connection conn;
    User user = new User();
    
    public UserQuery(Connection conn)
    {
        this.conn = conn;
    }
    
    
    public boolean checkUser(String username, String password)throws SQLException, Exception{        
        String position = null;
        String name = null;
        
        boolean verify = false;
        int delete =0;
        String query = "select concat(firstName,' ' ,lastName) AS 'name', position, username, password FROM companypersonneldata where username = ? AND password = ?";
        PreparedStatement prest = conn.prepareStatement(query);
        prest.setString(1, username);
        prest.setString(2, password);
        ResultSet rs = prest.executeQuery();
        while(rs.next())
        {
            position = rs.getString("position");
            name = rs.getString("name");
            delete++;
        }
        
        System.out.println(delete);
        if(delete ==1){
            System.out.println("Log-In is a Success");
            verify = true;
            user.setUserName(username);
            user.setPosition(position);
            user.setName(name);
        }
        return verify;
        } 
    
    public String getName()
    {
        return user.getName();
    }
    
    
}
